//获取头像个人信息以及作品
//获取头像和获取个人信息
var data = ""
var length = 0
var max_page = parseInt(length / 16)
var remain = length % 16
if(remain != 0 && length > 16) {
	max_page = max_page + 1
}

var data_prize = ""
var length_prize = 0
var max_page_prize = parseInt(length / 16)
var remain_prize = length_prize % 16
if(remain_prize != 0 && length_prize > 16) {
	max_page_prize = max_page_prize + 1
}

//导航栏
$('#f-nav').tooltip({
	default: 1, // 默认为空  --  选中默认值
	type: 'slideMove', // 必填, 选择内容
	success: function(ret) {} //初始化回调
});
var li = 0
$("#li_one").click(function() {
	if(li == "1") {
		$(".works_span_one").css("animation", "work_show 0.4s ease-in-out forwards")
		$(".works_span_tow").css("animation", "work_disappear 0.4s ease-in-out forwards")
		li = 0
	}
})
$("#li_tow").click(function() {

	if(li == "0") {
		$(".works_span_one").css("animation", "work_disappear 0.4s ease-in-out forwards")
		$(".works_span_tow").css("animation", "work_show 0.4s ease-in-out forwards")
		li = 1
	}
})

var now_page = parseInt($("#now_page").text())
if($.cookie('uId')) {
	//获取作品uId
		$.ajax({
			type: "post",
			url: "",
			async: true,
			complete: function(res) {
				if(res.readyState == 4 && res.status == 200) {
					var obj = JSON.parse(res.responseText)
					data=obj.data
					length =obj.data.length()
				}
			},
		});
	//获取作品
		var proName_p
		var cover
		$.ajax({
			type: "post",
			url: "",
			async: true,
			complete: function(res) {
				if(res.readyState == 4 && res.status == 200) {
					var obj = JSON.parse(res.responseText)
					for(var i = 0; i < length; i++) {
						proName[i] = obj.data.proName
						cover[i]=obj.data.cover
					}
					for(var i = 0; i < length; i++) {
						if(obj.data.prize==1){
							proName_prize[i] = obj.data.proName
							cover_prize[i]=obj.data.cover
						}
						
						
					}
					
				}
			},
		});
	//作品处理逻辑
	works_jubge()
	//实战
		function works_jubge() {
			if(li == 0) {
				if(now_page < max_page) {
					$("#works").empty()
					$("#works").append(
						`<span class="works_data_text">
						${length}
				</span>
				<span class="works_search_bg_text">
					Search.....
				</span>
				<input type="text" id="works_search" maxlength="20" value="" />	
				<input type="button" id="works_search_but" value="" />`
					)
	
					for(var i = 0; i < 16; i++) {
						var pg = now_page - 1
	
						$("#works").append(
						`<div class="work_div">
						<span class="work_name">${proName[pg*16+i]}<span>
						<img class="work_img"/ src="
							${cover[pg*16+i]}
						">
						<div class="work_dateAndLove">
							<span class="work_date">
								${data[pg*16+i].date}		
							</span>
							<span class="work_love">
								${47}	
							</span>
						</div>
					</div>`
						)
					}
				} else if(now_page == max_page) {
					$("#works").empty()
					$("#works").append(
						`<span class="works_data_text">
						${length}
						</span>
						<span class="works_search_bg_text">
						Search.....
						</span>
						<input type="text" id="works_search" maxlength="20" value="" />	
						<input type="button" id="works_search_but" value="" />`
					)
					for(var i = 0; i < remain; i++) {
						$("#works").append(
							`<div class="work_div">
						<span class="work_name"> ${proName[pg*16+i]}<span>
						<img class="work_img" src="${cover[pg*16+i]}"/>
						<div class="work_dateAndLove">
							<span class="work_date">
									${data[pg*16+i].date}
							</span>
							<span class="work_love">
								${47}
							</span>
						</div>
					</div>`
						)
					}
				}
			}
			else if(li==1){
				if(now_page < max_page_prize) {
					alert(now_page)
					alert(max_page_prize)
					
					$("#works").empty()
					$("#works").append(
						`<span class="works_data_text">
						${length}
				</span>
				<span class="works_search_bg_text">
					Search.....
				</span>
				<input type="text" id="works_search" maxlength="20" value="" />	
				<input type="button" id="works_search_but" value="" />`
					)
	
					for(var i = 0; i < 16; i++) {
						var pg = now_page - 1
	
						$("#works").append(
						`<div class="work_div">
						<span class="work_name">${proName_prize[pg*16+i]}<span>
						<img class="work_img" src="${cover_prize[pg*16+i]}"/>
						<div class="work_dateAndLove">
							<span class="work_date">
									${data_prize[pg*16+i].date}
							</span>
							<span class="work_love">
								${47}
							</span>
						</div>
					</div>`
						)
					}
				} else if(now_page == max_page_prize) {
					$("#works").empty()
					$("#works").append(
						`<span class="works_data_text">
						${length}
						</span>
						<span class="works_search_bg_text">
						Search.....
						</span>
						<input type="text" id="works_search" maxlength="20" value="" />	
						<input type="button" id="works_search_but" value="" />`
					)
					for(var i = 0; i < remain_prize; i++) {
						$("#works").append(
							`<div class="work_div">
						<span class="work_name">${proName_prize[pg*16+i]}<span>
						<img class="work_img" src="${cover_prize[pg*16+i]}"/>
						<div class="work_dateAndLove">
							<span class="work_date">
									${data_prize[pg*16+i].date}
							</span>
							<span class="work_love">
								${47}
							</span>
						</div>
					</div>`
						)
					}
				}
				
			}
		}
	//翻页

	$("#front_page").click(function() {

		if(now_page > 1) {
			now_page = now_page - 1;
			$("#now_page").text(now_page);
		}
		works_jubge()
	})
	$("#back_page").click(function() {

		if(now_page < max_page) {
			now_page = now_page + 1
			$("#now_page").text(now_page);
		}
		works_jubge()
	})
	//切换
	$("#li_one").click(function() {
		$("#now_page").text("1")
		now_page = parseInt($("#now_page").text())
		works_jubge()
	})

	$("#li_tow").click(function() {
		$("#now_page").text("1")
		now_page = parseInt($("#now_page").text())
		works_jubge()
	})
	//搜索
	$("#works_search_but").click(function() {
		if($("#works_search").val()) {}
	})

	//搜索栏
	$("#works_search").focus(function() {
		$(".works_search_bg_text").text("")
	})
	$("#works_search").blur(function() {
		if($("#works_search").val() != "") {
			$(".works_search_bg_text").text("")
		} else {
			$(".works_search_bg_text").text("Search.....")
		}
	})
}